package edu.jd.software.web.backend.controller;

import edu.jd.software.web.backend.common.api.CommonResult;
import edu.jd.software.web.backend.dto.MinioUploadDto;
import edu.jd.software.web.backend.service.MinioService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

import java.io.InputStream;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;

import static jakarta.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;


@Controller
@Tag(name = "MinioTestController", description = "MinIO对象存储管理(固定目录)")
@RequestMapping("/minioTest")
public class MinioTestController {

    private static final Logger LOGGER = LoggerFactory.getLogger(MinioTestController.class);

    @Autowired
    private MinioService minioService;


    @Value("${minio.testDir}")
    private String testdir;


    @Operation(summary = "上传文件(固定目录)",description = "MinIO的文件上传")
    @RequestMapping(value = "/upload",consumes = "multipart/form-data",method = RequestMethod.POST)
    @ResponseBody
    public CommonResult upload( @Parameter(description = "上传的文件", required = true,
            schema = @Schema(type = "string", format = "binary")) @RequestPart("file") MultipartFile file) {

        return CommonResult.failed();
    }

    @GetMapping("/download")
    @Operation(summary = "流式下载(固定目录)", description = "适合大文件的分块下载")
    public StreamingResponseBody streamDownload(
            @RequestParam String  objectName,
            HttpServletResponse response) {

            return null;
    }


    @Operation(description = "文件删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delete(@RequestParam("objectName") String objectName) {

        return CommonResult.failed();
    }
}
